package com.mynetwork.data;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;

import org.json.JSONException;
import org.json.JSONObject;

import com.mynetwork.utils.Size;

import android.content.Context;
import android.util.Log;


public class AppUniqueIdManager extends NetworkManager {
	private static final String TAG = "NewsManager";
	protected boolean sIsUpdate = false;
	
	public OnNetworkListener mOnNetworkListener;
	
	
	public AppUniqueIdManager() {}
	

	//[[ Network ------------------------------------------------------------------------
	
	public void download(Context context, OnNetworkListener l) {
		super.download(context, l);
	}
	
	public void init(Context context) {
	}
	

	@Override
    public HttpURLConnection getConnection() throws IOException {
    	HttpURLConnection conn = NetworkManager.getUrlConnection(NetworkManager.getApiServerURL() + NetworkManager.APP_UNIQUE_NUMBER);
			StringBuilder strBuilder = new StringBuilder();
			strBuilder.append("&app_id=" + AppData.APP_PACK_NAME);
			strBuilder.append("&model=" + AppData.DEVICE_MODEL);
			strBuilder.append("&os_ver=" + AppData.OS_VERSION);
			strBuilder.append("&lcd_size=" + Size.DisplayWidth + "x" + Size.DisplayHeight);
			strBuilder.append("&store_type=" + getStoreType());
			strBuilder.append("&app_ver=" + AppData.APP_VERSION);
		Log.e(TAG,"KDS3393_url = " + NetworkManager.getApiServerURL() + NetworkManager.APP_UNIQUE_NUMBER + strBuilder.toString());
		OutputStreamWriter outStream = new OutputStreamWriter(conn.getOutputStream(), "UTF-8"); 
        PrintWriter writer = new PrintWriter(outStream); 
        writer.write(strBuilder.toString()); 
        writer.flush(); 
    	return conn;
    }
	
	@Override
    public boolean jsonParser(JSONObject jsonObj) throws JSONException {
		String appId = jsonObj.getString("appUniqueNo");
        if (appId != null) {
        	AppData.APP_ID = appId;
        }
        return true;
    }
	
	@Override
	public void getLocalData(){
		
	}
}
